package 数据结构和算法.算法.递归.数组内部最大值;

import java.util.Date;
import java.util.Random;

public class ArrayMax {
    public static void main(String[] args) {
        int[] array = {10000, 11500, 12000, 12500, 13000};
        test(array);
    }

    public static void test(int[] arrays) {
        for (int j : arrays) {
            int[] array = new int[j];
            Random random = new Random();//默认构造方法
            for (int i = 0; i < j; i++) {
                array[i] = random.nextInt(100000);
            }


            System.out.println("《《《《《《《元素个数为：" + j + " >>>>>>>>>>>>>");
            Date date1 = new Date();
            max(array);
            Date date2 = new Date();
            long cha1 = date2.getTime() - date1.getTime();
            System.out.println(date2.getTime() - date1.getTime());
            getMax(array, 0, array.length - 1);
            Date date3 = new Date();
            long cha2 = date3.getTime() - date2.getTime();
            System.out.println(date3.getTime() - date2.getTime());
            System.out.println("《《《《《《》》》》》》》》》》》");
        }
    }


    public static int getMax(int[] array, int l, int r) {
        if (l == r) {
            return array[l];
        } else {
            int a = array[l];
            int b = getMax(array, l + 1, r);
            if (a > b) {
                return a;
            } else {
                return b;
            }
        }
    }

    public static int max(int array[]) {
        int max = 0;
        for (int i = 0; i < array.length; i++) {
            if (i == 0) {
                max = array[i];
            } else {
                if (max < array[i]) {
                    max = array[i];
                }
            }
        }

        return max;
    }
}
